package searchInsert;

public class Solution {
    public int searchInsert(int[] nums, int target) {
        // 查找插入位置
        // 二分法
        int r = nums.length-1;
        int l = 0;
        int mid = 0;
        while (l<r){
            mid = l+(r-l)>>1;
            if(nums[mid]<target){
                l = mid-1;
            }else if(nums[mid]>target){
                r = mid+1;
            }else{
                return mid;
            }
        }
        return mid+1;
    }

    // 1 2  3  5  8  9     6
    //         l  mid  r
    //
}
